
const  order_template = '<div>' +
'   <div class="content page-order"  style="padding-bottom:2.5rem;overflow-x: hidden;">' +
'       <div class="orderQueue">' +
'           <div class="orderTitle">' +
'               <label>当前委托</label>' +
'               <span class="button f-fr" v-on:click=cancel_all()>全部撤销</span>' +
'               <span class="button f-fr" :class="{no_active:is_not_select_all}"  style="margin-right:1rem;" v-on:click=select_all()>显示所有币种</span>' +
'           </div>' +
'           <div v-if="list.length==0" class="noData">' +
'               <img src="/static/app/images/noData.png"/>' +
'               <p>暂无当前委托</p>' +
'           </div>' +
'           <div class="order" v-for="info in list" >' +
'               <div >' +
'                   <span class="symbol">{{info.up_coin_type}} / {{info.up_use_coin_type}}  ' +
'                       <span v-bind:class="{green:info.is_buy, magenta:info.is_sell }">{{info.order_title}}</span>'+
'                   </span>' +
'                   <span class="button f-fr" v-on:click=cancel_order(info.id)>撤销</span>' +
'                   <div class="time gray">2018-03-21 10:51:10</div>' +
'               </div>' +
'               <div v-if="info.is_buy">' +
'                   <table style="width: 100%">' +
'                   <tbody>' +
'                       <tr>' +
'                           <th class="f-center">{{info.price}}</th>' +
'                           <th class="f-center">{{info.count}}</th>' +
'                           <th class="f-center">{{info.finish}}</th>' +
'                       </tr>' +
'                      <tr>' +
'                           <td class="f-center gray">委托价格</td>' +
'                           <td class="f-center gray">委托数量</td>' +
'                       <td class="f-center gray">已成交数量</td>' +
'                       </tr>' +
'                   </tbody>' +
'                   </table>' +
'               </div>' +
'               <div v-if="info.is_sell">' +
'                   <table style="width: 100%">' +
'                   <tbody>' +
'                       <tr>' +
'                           <th class="f-center">{{info.price}}</th>' +
'                           <th class="f-center">{{info.amount}}</th>' +
'                           <th class="f-center">{{info.finish_amount}}</th>' +
'                       </tr>' +
'                      <tr>' +
'                           <td class="f-center gray">委托价格</td>' +
'                           <td class="f-center gray">委托金额</td>' +
'                       <td class="f-center gray">已成交金额</td>' +
'                       </tr>' +
'                   </tbody>' +
'                   </table>' +
'               </div>' +
'          </div>' +
'       </div>' +
'   </div>' +
'</div>'

order_list = [
    //    {
        //        "coin_type" : "BTC",
        //        "use_coin_type" : "BITCNY",
        //        "up_coin_type" : "BTC",
        //        "up_use_coin_type" : "BITCNY",
        //        "order_title" : "买入",
        //        "is_buy" : true,
        //        "is_sell" : false,
        //        "price" : "2000.00",
        //        "count" : "10.00",
        //        "finish" : "5.00",
    //    },
    //    {
        //        "up_coin_type" : "BTC",
        //        "up_use_coin_type" : "BITCNY",
        //        "coin_type" : "USB",
        //        "use_coin_type" : "BITCNY",
        //        "order_title" : "卖出",
        //        "is_buy" : false,
        //        "is_sell" : true,
        //        "price" : "200.00",
        //        "amount" : "50000.00",
        //        "finish_amount" : "6000.00",
    //    },
]
order_data = {
    "list" : order_list,
    "coin_type" : "",
    "use_coin_type" : "",
    "up_coin_type" : "",
    "up_use_coin_type" : "",
    "is_not_select_all" : false,
}
const ORDER = {
    template : order_template,
    data: function () {
        // 初始化
        //

        return order_data
    },
    computed: {
    },

    created:function () {
        // get all list
        this.is_not_select_all=true
        order_data.coin_type=dict.coin_type
        order_data.use_coin_type=dict.use_coin_type
        order_data.up_coin_type=dict.coin_type.toUpperCase()
        order_data.up_use_coin_type=dict.use_coin_type.toUpperCase()
        this.get_order_list()
    },

    methods:{
        cancel_all : function () {
            var content = '你确定要撤销全部挂单么'
            var style = 'border:none; background-color:#fff; color:#333;border-radius:0px'
            layer.open({
                content: content
                ,btn: ['确定', '取消']
                ,style:style
                ,yes: (index) => {
                    this.cancel_all2()
                }
            });
        },
        cancel_all2 : function () {
            //console.log("cancel all " + this.coin_type)
            params = {type:"-1", coin_type: this.coin_type, use_coin_type: this.use_coin_type}
            if (!this.is_not_select_all)
            {
                params = {type:"-1"}
            }

            $.post("/btc/delete_all_order",
            params,
            (data) => {
                console.log("cancel order")
                console.log(params)
                console.log(data)
                if (data.result == 'true')
                {
                    content = "撤销成功"
                    this.get_order_list();
                }
                else
                {
                    content = "撤销失败，请稍后再试"
                }
                var style = 'border:none; background-color:#fff; color:#333;border-radius:0px'
                layer.open({
                    type:0,
                    content: content,
                    skin: 'msg',
                    time: 3 ,//2秒后自动关闭
                    style: style,
            });

        });
    },
    cancel_order : function (orderid) {
        var content = '你确定要撤销该挂单么'
        var style = 'border:none; background-color:#fff; color:#333;border-radius:0px'
        layer.open({
            content: content
            ,btn: ['撤销', '取消']
            ,style:style
            ,yes: (index) => {
                this.cancel_order2(orderid)
            }
        });
    },
    cancel_order2 : function (orderid) {
        //console.log("cancel order " + this.coin_type)
        $.post("/btc/order_delete",
        {orderid: orderid},
        (data) => {
            //console.log("cancel order " + tips)
            //console.log(data)
            if (data.status == true)
            {
                content = "撤销成功"
                this.get_order_list();
            }
            else
            {
                content = "撤销失败，请稍后再试"
            }
            var style = 'border:none; background-color:#fff; color:#333;border-radius:0px'
            layer.open({
                type:0,
                content: content,
                skin: 'msg',
                time: 3 ,//2秒后自动关闭
                style: style,
        });
    });
},
get_order_list:function()
{
    params = {coin_type: this.coin_type, use_coin_type: this.use_coin_type}
    if (!this.is_not_select_all)
    {
        params = {}
    }
    console.log("debug ")
    console.log(params)
    $.post("/btc/get_order_list", params,
    (data) =>{
        if (data.length == 0) {
            return 0
        }
        var jsonobj = data
        jsonobj.reverse(),
        console.log("getorder "  + JSON.stringify(jsonobj))
        order_list = []
        for (var i=0; i < jsonobj.length; i++)
        {

            info = jsonobj[i]
            row = {}
            row.id = info.id
            row.coin_type = info.coin_type
            row.use_coin_type = info.use_coin_type

            row.up_coin_type = row.coin_type.toUpperCase()
            row.up_use_coin_type = row.use_coin_type.toUpperCase()

            row.price = info.price
            row.count = info.count
            row.amount = info.amount
            row.finish = info.finish
            row.finish_amount = info.finish_amount
            if (info.order_type == 1 || info.order_type == 11)
            {
                row.is_buy = true
                row.is_sell = false
                row.order_title = '买入'
            }
            else
            {
                row.is_buy = false
                row.is_sell = true
                row.order_title = '卖出'
            }
            order_list.push(row)
        }

        this.list = order_list
        //var data = {
            //    coin0: g_coin0,
            //    coin1: g_coin1,
            //    coin0_info: g_coin_info[g_coin0],
            //    coin1_info: g_coin_info[g_coin1],
            //    jsonobj: jsonobj.reverse(),
            //}
        });
    },
    select_all:function(){
        if (this.is_not_select_all)
        {
            this.is_not_select_all=false
        }
        else
        {
            this.is_not_select_all=true
        }
        this.get_order_list()
    }
}
};

